package com.fh.controller.generalview;

import com.fh.controller.base.BaseController;
import com.fh.model.Page;
import com.fh.service.generalview.IGeneralViewService;
import com.fh.util.Const;
import com.fh.util.CountMoneyUtil;
import com.fh.util.PageData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * @Author LiGuangYi Date: 2017/9/21 14:14
 * @description:
 */
@Controller
@RequestMapping(value = "/general/view")
public class GeneralViewController extends BaseController {

    @Autowired
    private  IGeneralViewService generalViewService;


    /**
     * 进入列表页面不展示数据
     * @return
     */
    @RequestMapping(value="/list")
    public ModelAndView list(){
    	ModelAndView mv =this.getModelAndView();
    	mv.setViewName("generalview/generalView");
        return mv;
    }
    
    @RequestMapping(value = "/resultList")
    public ModelAndView viewList(Page page){
        ModelAndView mv =this.getModelAndView();
        PageData pageData=this.getPageData();
        String sortbylasttime = pageData.getString("sortbylasttime");
        if (!StringUtils.isEmpty(sortbylasttime)) {
            if (Const.SING_STATUS_STRING_ZERO.equals(sortbylasttime)) {
                pageData.put("sortFind", "last_call_time,repayment_id");
                mv.addObject("sortbylasttime", Const.SING_STATUS_ZERO);
            } else if (Const.SIGN_STATUS_STRING_ONE.equals(sortbylasttime)) {
                pageData.put("sortFind", "last_call_time DESC,repayment_id");
                mv.addObject("sortbylasttime", Const.SIGN_STATUS_ONE);
            }
        }else{
            pageData.put("sortFind", "create_time DESC,repayment_id");
        }
        page.setPd(pageData);
        List<PageData> generalViewlistPage = generalViewService.findGeneralViewlistPage(page);
        mv.addObject("pagelist",generalViewlistPage);
        //mv.addObject("countMoney", CountMoneyUtil.getCountMoney(generalViewlistPage));
        mv.addObject("pd", pageData);
        mv.setViewName("generalview/generalView");
        return mv;
    }
}
